﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Meqs.Entity;
using Meqs.Logic;
using Meqs.Logic.Interface;
public partial class Custom_SchoolYearWeeks : System.Web.UI.UserControl
{
    protected IList<TermInfo> terms = new List<TermInfo>();
    protected IList<WeeksInfo> weeks = new List<WeeksInfo>();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SchoolInfo si = SchoolCommon.Sch_SchoolInfo;
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", si.SchoolMark);
            //ht.Add("SchoolYear", si.SchoolYear);
            //ht.Add("Term", si.SchoolTerm);
            terms = Container<ITermInfoLogic>.Instance.FindAll(ht);



            DateTime now = DateTime.Now;
            int index = 0;
            foreach (TermInfo t in terms)
            {
                DateTime stime = Convert.ToDateTime(t.StartDate);
                DateTime etime = Convert.ToDateTime(t.EndDate);
                if (index == 0)
                {
                    etime = DateTime.Now;
                }
                else
                {
                    etime = Convert.ToDateTime(terms[index - 1].StartDate);
                }
                WeeksInfo yml = new WeeksInfo();
                yml.schoolyear = t.SchoolYear;
                yml.term = t.Term;
                yml.weekindex = GetYearAndWeeks(stime, etime);
                weeks.Add(yml);
                index++;
            }
        }
    }

    private List<int> GetYearAndWeeks(DateTime stime, DateTime etime)
    {
        List<int> temp = new List<int>();
        if (stime < etime)
        {
            TimeSpan spanTime = (etime - stime);
            int maxindex = spanTime.Days / 7 + 1;
            for (int i = 1; i <= maxindex;i++ )
            {
                temp.Insert(0, i);
            }
        }
        return temp;
    }
}
public class WeeksInfo
{
    public int schoolyear = 0;
    public int term = 0;
    public List<int> weekindex = new List<int>();
}